package lgvalle.com.fluxtodo.flux.fluxbase;

import de.greenrobot.event.Subscribe;
import de.greenrobot.event.ThreadMode;

/**
 * Created by lgvalle on 02/08/15.
 */
public abstract class Store {

    // 分发器
    final Dispatcher dispatcher;

    // 单例的store 依赖注入分发器
    public Store(Dispatcher dispatcher) {
        this.dispatcher = dispatcher;
    }

    // 发送一个通知 store 状态改变过了
    protected void notifyStoreChanged(StoreChangeEvent event) {
        dispatcher.notifyStoreChangedToUI(event);
    }

    //abstract StoreChangeEvent changeEvent(StoreChangeEvent event);
    // 收到action的方法
    @Subscribe(threadMode = ThreadMode.MainThread)
    public void onEventMainThread(Action action){
        onActionReceive(action);}

    protected abstract void onActionReceive(Action action) ;

    public interface StoreChangeEvent {}
}
